<?php

function sef_event_request_beforeOutput($arg){
	if(App::getConfig('sef')->getRewriteable()){
		$arr = $GLOBALS[RC]->getCollectedUrls(array());
		$urls = App::getBusiness('sef/rewrite_flow_output')->run($arr);
		$cnt = $GLOBALS[RC]->getResponse()->getContent();
		foreach($urls as $source=>$rewrite){
			$cnt = str_replace(sprintf(App::getConfig('sef')->getTagFormat(), $source), $rewrite, $cnt);
		}
		$GLOBALS[RC]->getResponse()->setContent($cnt);
	}

    $content = App::getBusiness('system/localize')->replateLangTag(
            $GLOBALS[RC]->getResponse()->getContent());
    $GLOBALS[RC]->getResponse()->setContent($content);
}
Soul_Event_Manager::registerListener('request.beforeOutput', 'sef_event_request_beforeOutput');

function sef_event_request_beforeRoute($arg){	
	if(App::getConfig('sef')->getRewriteable()){
		App::getBusiness('sef/rewrite_flow_route')->run();
	}
}
Soul_Event_Manager::registerListener('request.beforeRoute', 'sef_event_request_beforeRoute');